﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindStyle.WindowsLiveWriter.Plugin.ExifInfo
{
    public partial class TemplateEditor : Form
    {
        public TemplateEditor()
            : this(new Template()) { }

        public TemplateEditor(Template template)
        {
            InitializeComponent();
            this.HtmlTemplate = template;

            this.BindControls();
        }

        public Template HtmlTemplate { get; private set; }

        private void BindControls()
        {
            this.tb_TemplateName.Text = this.HtmlTemplate.Name;
            this.tb_HtmlTemplate.Text = this.HtmlTemplate.HtmlTemplate;
        }

        private void InsertPlaceholder(string placeholder)
        {
            this.tb_HtmlTemplate.Text
                = this.tb_HtmlTemplate.Text.Insert(this.tb_HtmlTemplate.SelectionStart,
                "*" + placeholder + "*");
        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            this.HtmlTemplate.Name = this.tb_TemplateName.Text;
            this.HtmlTemplate.HtmlTemplate = this.tb_HtmlTemplate.Text;
        }

        private void btn_Insert_PlaceHolder_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                Button btn = sender as Button;
                if (btn.Tag != null)
                    this.InsertPlaceholder(btn.Tag.ToString());
            }
        }
    }
}
